#include "widget.h"
#include "ui_widget.h"
#include "gameselect.h"
#include <QPainter>
#include <QIcon>
#include <QPushButton>
#include <QFont>
#include <QSound>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //设置窗口的大小
    this->setFixedSize(1000,700);

    //设置窗口的图标
    this->setWindowIcon(QIcon(":res/icon.png"));

    //设置窗口的标题
    this->setWindowTitle("贪吃蛇大作战");

    //创建主页大厅的开始按钮，设置位置，字体和样式
    QPushButton* strBtn = new QPushButton(this);
    strBtn->setText("开始游戏");
    strBtn->move(430,610);
    //创建字体对象
    QFont font("华文行楷",20);
    strBtn->setFont(font);
    QString style("");
    style+="QPushButton:hover { color: white; }";
    style+="QPushButton {border:0px;}";
    strBtn->setStyleSheet(style);

    GameSelect * gameselect = new GameSelect;
    connect(strBtn,&QPushButton::clicked,[=](){
        this->close();
        gameselect->show();
        gameselect->setGeometry(this->geometry());
        QSound::play(":res/clicked.wav");

    });

}

Widget::~Widget()
{
    delete ui;
}

void Widget::paintEvent(QPaintEvent *event)
{
    (void)event;
    //实例话一个绘画者
    QPainter painter(this);

    //创建绘画工具
    QPixmap map(":res/hall_back.png");

    //使用绘画工具将背景绘画到窗口上
    painter.drawPixmap(0,0,this->width(),this->height(),map);


}

